<!DOCTYPE html>
<html lang="en">
<head>
        <?php include_once VIEWS.'/inc/head.php'; ?>

</head>
<body>
 <div class="box"></div>

    <?php include_once VIEWS.'/inc/header.php'; ?>
    <!--头部导航-->
     <?php include_once VIEWS.'/inc/nav.php'; ?>
     <!--分隔-->
  <div class="wrap clear">
       
    
        <!--banner大图-->
    
        <div class="main news js-win-h js-news">
        <div class="box">
            <div class="calendar">
        		<div class="wrap2">
                    <div class="cal-week">
                        <ul class="f-cb">
                            <li class="pull-left">日</li>
                            <li class="pull-left">一</li>
                            <li class="pull-left">二</li>
                            <li class="pull-left">三</li>
                            <li class="pull-left">四</li>
                            <li class="pull-left">五</li>
                            <li class="pull-left">六</li>
                        </ul>
                    </div>
                    <div class="cal-day">
                        <ul class="f-cb">
                            
                        </ul>
                    </div>
                </div>
                <div class="cal-bar f-cb">
                    <a id="prev-moon" class="pull-left" href="javascript:void(0)"></a>
                    <p class="cal-ym pull-left"><span class="cal-year">2016</span>.<span class="cal-moon">5</span></p>
                    <a id="next-moon" class="pull-left" href="javascript:void(0)"></a>
                </div>  
            </div>
        </div>
    </div>
         
      <!--分隔-->

  </div>





 
    <!--商业区域-->

<script type="text/javascript">
    $(function(){
        $('.js-nar-bar .link').eq(3).addClass('cur');
        
        //日历
        var moon_cn = new Array();
        var data_arr= new Array();
        moon_cn[1] = "1";
        moon_cn[2] = "2";
        moon_cn[3] = "3";
        moon_cn[4] = "4";
        moon_cn[5] = "5";
        moon_cn[6] = "6";
        moon_cn[7] = "7";
        moon_cn[8] = "8";
        moon_cn[9] = "9";
        moon_cn[10] = "10";
        moon_cn[11] = "11";
        moon_cn[12] = "12";
        var _today = new Date();
        var _today_y = _today.getFullYear();
        var _today_m = _today.getMonth();
        var _today_d = _today.getDate();
        var now_y = _today_y;
        var now_m = _today_m;
        function showdate(y,m){
            /*模拟数据*/
            // 日期，对应日期的数据条数
        	data_arr=[
                      <?php foreach($news as $k=>$v):?>
                ['<?php echo $k;?>',<?php echo $v;?>],
                			<?php endforeach;?>
            ];
            var m = m+1;
            if(m == 12){
                var nextm = 1;
                var nexty = y+1;
            }else{
                var nextm = m+1;
                var nexty = y;
            }


            var new_date = new Date(y+"/"+m+"/1");//取第一天  
            var new_nextdate = new Date(nexty+"/"+nextm+"/1");//取下个月第一天
            var new_day = new_date.getDay();//取第一天是星期几
            var d_num = (new Date(new_nextdate.getTime()-1000*60*60*24)).getDate();//取总天数
            var d_prev_num = (new Date(new_date.getTime()-1000*60*60*24)).getDate();//取上月总天数
            var laster_day = (new Date(new_nextdate.getTime()-1000*60*60*24)).getDay();//取最后一天周几
            var _d_prev_day = d_prev_num - new_day + 1;
            var _ist=0;
            $(".cal-day ul").html("");
            if(y == _today_y && m == _today_m + 1){
                _ist = 1;
            }
            for (var i = 0; i < new_day; i++) {
                /*后--添加非本月的日期*/
                var _d = _d_prev_day + i;
                
                $(".cal-day ul").append("<li class='pull-left'> </li>");
            }
            /* var data_arr[j][0].split("-");*/
            function addRed(_data_arr,_date_sw,_i){
                var count_sw=0;
                var _num_sw;
                for(var j=0;j<_data_arr.length;j++){
                    if(_data_arr[j][0]==_date_sw){
                        num_f=j;
                        count_sw++;
                        _num_sw=_data_arr[j][1];
                    }
                }

                if(count_sw<1){
                    $(".cal-day ul").append( "<li class=' pull-left' data-id='"+_date_sw+"'>"+_i+"</li>"); 
                }else if(count_sw==1){
                    if(_num_sw>1){
                    	$(".cal-day ul").append( "<li class=' pull-left red' data-num='"+_data_arr[num_f][1]+"' data-id='"+_date_sw+"'> <a href='<?php echo  site_url("activity/list?id="); ?>"+_date_sw+"'> "+_i+" </a></li>");
                    }else{
                    	$(".cal-day ul").append( "<li class=' pull-left red' data-num='"+_data_arr[num_f][1]+"' data-id='"+_date_sw+"'> <a href='<?php echo  site_url("activity/info?news_id="); ?>"+_date_sw+"'> "+_i+" </a></li>");
                    }
                }
               
            }
            function addGray(_data_arr,_date_sw,_i){
                var count_sw=0;
                var _num_sw;
                for(var j=0;j<_data_arr.length;j++){
                    if(_data_arr[j][0]==_date_sw){
                        num_f=j;
                        count_sw++; 
                         _num_sw=_data_arr[j][1];
                    }
                }
                if(count_sw<1){
                    $(".cal-day ul").append( "<li class=' pull-left' data-id='"+_date_sw+"'>"+_i+"</li>"); 
                }else if(count_sw==1){
                    if(_num_sw>1){
                    	$(".cal-day ul").append( "<li class=' pull-left gray' data-num='"+_data_arr[num_f][1]+"' data-id='"+_date_sw+"'> <a href='<?php echo  site_url("activity/list?id="); ?>"+_date_sw+"'> "+_i+" </a></li>");
                    }else{
                    	$(".cal-day ul").append( "<li class=' pull-left gray' data-num='"+_data_arr[num_f][1]+"' data-id='"+_date_sw+"'> <a href='<?php echo  site_url("activity/info?news_id="); ?>"+_date_sw+"'> "+_i+" </a></li>");
                    }
                }
            }
            function get_unix_time(dateStr)
            {
                var date =  new Date(newstr); 
                var time_str = date.getTime().toString();
                return time_str.substr(0, 10);
            }
            for (var i = 1; i <= d_num; i++) {
                var date_sw=y+'-'+m+'-'+i;

                var num_f =0;
                if(_ist == 1 && i == _today_d){
                    var count_sw=0;
                    var _num_sw;
                    for(var j=0;j<data_arr.length;j++){
                        if(data_arr[j][0]==date_sw){
                            num_f=j;
                            count_sw++; 
                             _num_sw=data_arr[j][1];
                        }
                    }
                    if(count_sw<1){
                        $(".cal-day ul").append( "<li class='today pull-left' data-id='"+date_sw+"'>"+i+"</li>"); 
                    }else if(count_sw==1){
                        if(_num_sw>1){
                        	$(".cal-day ul").append( "<li class=' pull-left red' data-num='"+data_arr[num_f][1]+"' data-id='"+date_sw+"'> <a href='<?php echo  site_url("activity/list?id="); ?>"+_date_sw+"'> "+i+" </a></li>");
                        }else{
                        	$(".cal-day ul").append( "<li class=' pull-left red' data-num='"+data_arr[num_f][1]+"' data-id='"+date_sw+"'> <a href='<?php echo  site_url("activity/info?news_id="); ?>"+_date_sw+"'> "+i+" </a></li>");
                        }
                    }
                }else{
                    if(_today_y>y){
                        addGray(data_arr,date_sw,i);
                    }else if(_today_y<y){
                        addRed(data_arr,date_sw,i);
                    }else if(_today_y==y){
                        if(_today_m+1>m){
                            addGray(data_arr,date_sw,i);
                        }else if(_today_m+1<m){
                             addRed(data_arr,date_sw,i);
                        }else if(_today_m+1==m){
                            if(i<_today_d){
                                 addGray(data_arr,date_sw,i);
                            }else{
                                addRed(data_arr,date_sw,i);
                            }
                        }
                    }
                }
            }
            for (var i = 0; i < 6 - laster_day; i++) {
                /*前--添加非本月的日期*/
                var _d = i+1;
                $(".cal-day ul").append("<li class='pull-left'> </li>");
            };
            $(".cal-moon").html(moon_cn[m]);
            $(".cal-year").html(y);
        }
        function changeMoon(y,m){
            if( m < 0){
                var _m = 11;
                var _y = y - 1;
            }else if( m > 11){
                var _m = 0;
                var _y = y + 1;
            }else{
                var _m = m;
                var _y = y;
            }
            var _nowarr = new Array();
            _nowarr[1] = _m;
            _nowarr[0] = _y;
            return _nowarr;
        }
        $("#prev-moon").click(function(){
            var _pm = now_m - 1;
            var _nowarr = changeMoon(now_y,_pm);
            now_y = _nowarr[0];
            now_m = _nowarr[1];
            showdate(now_y,now_m);
        });
        $("#next-moon").click(function(){
            var _pm = now_m + 1;
            var _nowarr = changeMoon(now_y,_pm);
            now_y = _nowarr[0];
            now_m = _nowarr[1];
            showdate(now_y,now_m);
        });


        showdate(_today_y,_today_m);
    })
</script>

</body>
</html>

